<?php

class FrameAction extends Action {
	// 检查用户是否登录
	public $_SESSION;
	function _initialize() {
		import('@.ORG.Util.Session');
		$this -> _SESSION = Session::get_instance();
	}

	protected function checkUser() {
		if (!($this -> get_user_id())) {
			$this -> assign('jumpUrl', 'login');
			$this -> error('没有登录');
		}
	}

	// 顶部页面
	public function top() {
		C('SHOW_RUN_TIME', false);
		// 运行时间显示
		C('SHOW_PAGE_TRACE', false);
		$model = M("Node");
		if ($this -> _session('administrator')) {
			$where = array('status' => 1, 'pid' => 0, );
		} else {
			$where = array('status' => 1, 'pid' => 0, 'id' => array('neq', 84));
		}
		$list = $model -> where($where) -> order('sort asc') -> getField('id,name,url');
		$this -> assign("top_menu_rk", "top_menu_rk");
		$this -> assign('TopMenu', $list);
		$this -> assign('user_name', $this -> _session("user_name"));
		$this -> display();
	}

	// 尾部页面
	public function footer() {
		C('SHOW_RUN_TIME', false);
		// 运行时间显示
		C('SHOW_PAGE_TRACE', false);
		$this -> display();

	}

	// 菜单页面
	public function left() {

		$this -> checkUser();
		$auth_key = $this -> get_user_id();
		if ($auth_key) {
			if ($this -> _session('menu' . $auth_key)) {
				//如果已经缓存，直接读取缓存
				$menu = $this -> _session('menu' . $auth_key);
			} else {
				//读取数据库模块列表生成菜单项
				$menu = D("Node") -> access_list($auth_key);
				//缓存菜单访问
				$this -> _SESSION -> set('menu' . $auth_key, $menu);
			}

			$mail_folder = D("Code") -> mail_folder($auth_key);
			$doc_folder = D("DocFolder") -> doc_folder();
			$menu = array_merge($mail_folder, $menu, $doc_folder);

			if (!empty($_GET['node'])) {
				$tree = list_to_tree($menu, $_GET['node']);
				$this -> assign('menu', tree_menu($tree));
			}
			//dump($tree);
			$node = M("Node") -> find($_GET['node']);
			//dump($node["url"]);
			$this -> assign('default', $node["url"]);
		}
		C('SHOW_RUN_TIME', false);
		// 运行时间显示
		C('SHOW_PAGE_TRACE', false);
		$this -> display();
	}

}
?>